use palette::{Palette, Location, Extent};

struct Point2D(usize, usize);

impl Location for Point2D {
    fn locate(&self, extent: &Extent) -> Option<usize> {
        if let Extent::Planar(w, h) = extent {
            if self.0 < *w && self.1 < *h {
                Some(self.0 + self.1 * w)
            } else {
                None
            }
        } else {
            None
        }
    }
}

const STR_HELLO_WORLD: &str = "Hello, world!";
const STR_FOOBAR: &str = "Foobar";

fn main() {
    let mut p: Palette<String> = Palette::new(Extent::Planar(10, 10));
    p.insert(Point2D(0, 1), STR_FOOBAR.to_string());
    p.insert(Point2D(0, 0), STR_HELLO_WORLD.to_string());
    p.insert(Point2D(1, 0), STR_HELLO_WORLD.to_string());

    println!("{p:?}");

    p.remove(Point2D(0, 1));
    p.remove(Point2D(0, 0));

    println!("{p:?}");
}